package top.continew.wechat.user.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.continew.wechat.common.core.Result;
import top.continew.wechat.common.core.ResultCode;
import top.continew.wechat.common.exception.BusinessException;
import top.continew.wechat.user.dto.FriendDTO;
import top.continew.wechat.user.service.FriendService;
import top.continew.wechat.user.util.UserContextUtil;

import java.util.List;

/**
 * 好友关系控制器
 */
@RestController
@RequestMapping("/friends")
@RequiredArgsConstructor
public class FriendController {

    private final FriendService friendService;

    /**
     * 获取当前用户的好友列表
     *
     * @return 好友列表
     */
    @PostMapping("/list")
    public Result<List<FriendDTO>> getFriendList(@RequestBody FriendDTO friendDTO) {
        // 获取当前登录用户ID
//        Long userId = UserContextUtil.getCurrentUserId();
//        if (userId == null) {
//            throw new BusinessException(ResultCode.UNAUTHORIZED, "用户未登录");
//        }

        Long userId = friendDTO.getUserId();
        // 获取好友列表
        List<FriendDTO> friendList = friendService.getFriendList(userId);
        return Result.success(friendList);
    }
}
